package com.bstek.uflo.form.action.impl;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.bstek.dorado.view.View;
import com.bstek.uflo.form.Constants;
import com.bstek.uflo.form.action.FormData;
import com.bstek.uflo.service.ProcessService;
import com.bstek.uflo.service.StartProcessInfo;
import com.bstek.uflo.utils.EnvironmentUtils;

/**
 * @author Jacky.gao
 * @since 2013年11月16日
 */
@Component("uflo.form.saveDataAndStartProcessAction")
public class SaveDataAndStartProcessAction extends SaveFormDataAction {
	@Autowired
	@Qualifier(ProcessService.BEAN_ID)
	private ProcessService processService;
	public String getName() {
		return "发起流程";
	}

	public String getIcon() {
		return "url(>skin>common/icons.gif) -60px -220px";
	}

	public void onViewInit(View view) {
	}

	public void execute(FormData formData, Session session) {
		String businessId=saveFormData(formData, session);
		long processId=formData.getProcessId();
		StartProcessInfo info=new StartProcessInfo(EnvironmentUtils.getEnvironment().getLoginUser());
		info.setBusinessId(businessId);
		info.setCompleteStartTask(true);
		info.setTag(Constants.UFLO_FORM_PROCESS_TAG);
		Map<String,Object> variables=new HashMap<String,Object>();
		variables.put(Constants.TABLE_DEF_ID, formData.getTable().getId());
		info.setVariables(variables);
		processService.startProcessById(processId, info);
	}

	public String getClickScript(String actionId) {
		return null;
	}
}
